﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogisticsBLL;
using Model;

namespace WebLosgic.Carress
{
    public partial class ReceptionCarrier : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              int UserID = Convert.ToInt32(Session["UserIDs"]);
              GetBindCarrier();
            }
           
        }

        public void GetBindCarrier()
        {
            CarriessCyBLL bl = new CarriessCyBLL();
            int pageIdnex = AspNetPagerTool.CurrentPageIndex;
            int pageSzie = AspNetPagerTool.PageSize;
            int Count = 0;
            Carriers cars = new Carriers();
            cars.CarriesID = TxtnUber.Text;
            cars.LeaverDate = TxtCarrierDate.Text;
            cars.zhiDate = TxtCarrierDate2.Text;
            cars.SendLinkman = TxtFaPeople.Text;
            cars.ReceiveLinkman = TxtdetailPeople.Text;
            RptBindDrive.DataSource = bl.readCarrierRecepront(pageIdnex,pageSzie,out Count,cars);
            AspNetPagerTool.RecordCount = Count;
            RptBindDrive.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            GetBindCarrier();
        }

        protected void RptBindDrive_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "update")
            {
                int carrid = Convert.ToInt32(e.CommandArgument);
                CarriessCyBLL cyd = new CarriessCyBLL();
                int reult = cyd.SignCarries(carrid);
                string name = Session["names"].ToString();
                string Behavor = "" + name + ": 接收承运单";
                int TypeId = 17;
                int UserID = Convert.ToInt32(Session["UserIDs"]);
                string Parameters = @"" + carrid;
                string ProcName = "p_SignCarries";
                HttpRequest request = HttpContext.Current.Request;
                string IP = "192.168.0.1";
                int IsExcePion = 0;
                if (reult > 0)
                {
                    IsExcePion = 0;
                    int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
                    if (a > 0)
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('签收成功')", true);
                    }
                    GetBindCarrier();
                }
                else
                {
                    IsExcePion = 1;
                    int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
                    if (a > 0)
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('签收失败')", true);
                    }
                    GetBindCarrier();
                }
            }
        }

        protected void LinbntXiang_Click(object sender, EventArgs e)
        {
            int CarriesID = Convert.ToInt32(((LinkButton)sender).CommandArgument);
            Response.Redirect("Carriesdetails.aspx?ID="+CarriesID);
        }

        protected void AspNetPagerTool_PageChanged(object sender, EventArgs e)
        {
            GetBindCarrier();
        }
    }
}